package signUp;

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TestDemo {
    public static User signUp() {
        Scanner scan = new Scanner(System.in);
        User user = new User();
        System.out.println("请输入用户名");
        String username = scan.next();
        Pattern pattern = Pattern.compile("^\\w{6,20}$");
        Matcher matcher = pattern.matcher(username);
        if (matcher.find()) {
            System.out.println("请输入密码");
            String password = scan.next();
            pattern = Pattern.compile("^[\\dA-Za-z]{6,}$");
            matcher = pattern.matcher(password);
            if (matcher.find()) {
                System.out.println("请确认密码");
                String passwordTmp = scan.next();
                if (password.equals(passwordTmp)) {
                    System.out.println("请输入邮箱");
                    String email = scan.next();
                    pattern = Pattern.compile("^[\\dA-Za-z]+@[\\dA-Za-z]+\\.[a-z]+$");
                    matcher = pattern.matcher(email);
                    if (matcher.find()) {

                        user.setUsername(username);
                        user.setPassword(password);
                        user.setEmail(email);
                        System.out.println("注册成功");
                    } else {
                        System.out.println("邮箱不合法");
                    }

                } else {
                    System.out.println("两次密码不一致");
                }

            } else {
                System.out.println("密码不合法");
            }

        } else {
            System.out.println("用户名不合法");
        }

        return user;
    }

    public static void main(String[] args) {
        User user = signUp();

    }
}
